from . import gen, siliconflow
import json

model_ids = [
	'BAAI/bge-m3',
	'netease-youdao/bce-embedding-base_v1',
	'BAAI/bge-large-zh-v1.5',
	'BAAI/bge-large-en-v1.5',
	]

def emb(text, model_id='BAAI/bge-large-en-v1.5', api_key=None):
	if api_key is None:
		api_key = gen.next_api_key(siliconflow.api_keys)
	import requests
	url = "https://api.siliconflow.cn/v1/embeddings"
	payload = {
	    "model": model_id,
	    "input": text,
	    "encoding_format": "float"
	}
	headers = {
	    "Authorization": f"Bearer {api_key}",
	    "Content-Type": "application/json"
	}
	response = requests.request("POST", url, json=payload, headers=headers)
	embedding = json.loads(response.text)['data'][0]['embedding']
	return embedding
